<template>
  <div class="overview">
    <h3>系统概览</h3>
    <div class="title">
      <div class="device-count">
        <i class="iconfont">&#xe816;</i>
        <p><span>设备总数</span><span>{{ count.number }}</span></p>
      </div>
      <div class="money-count">
        <i class="iconfont">&#xe600;</i>
        <p><span>设备总金额</span><span>{{ count.amount }}</span></p>
      </div>

    </div>
    <div class="tu">
      <div class="circleView" ref="circle">

      </div>
      <div class="treeView" ref="tree">

      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  name: "OverView",
  data() {
    return {
      count: {},
      states: {},
      category: {}
    }
  },
  mounted() {
    this.$axios({
      method: "get",
      url: '/overview'
    }).then(res => {
      if (res.data.code == 0) {
        this.count = res.data.data
      }
    })

    this.$axios({
      method: "get",
      url: '/status-overview'
    }).then(res => {
      if (res.data.code == 0) {
        this.states = res.data.data
        let arr = [];
        this.states.value.forEach(element => {
          let obj = { value: element }
          arr.push(obj)
        });
        this.states.label.forEach((element, index) => {
          arr[index].name = element + ':' + arr[index].value
        });
        let myChart = echarts.init(this.$refs.circle);
        let option = {
          title: {
            text: '设备状态汇总',
            left: 'center',
            top: 15
          },
          series: [
            {
              type: 'pie',
              data: arr
            }
          ]
        };
        // 绘制图表
        myChart.setOption(option)

      }
    })
    this.$axios({
      method: "get",
      url: '/category-overview'
    }).then(res => {
      if (res.data.code == 0) {
        this.category = res.data.data
      }
      let myChart = echarts.init(this.$refs.tree);
      let option = {
        title: {
          text: "设备分类汇总",
          left: "center",
          top: 15
        },
        color: "#c03636",
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: this.category.label,
            axisTick: {
              alignWithLabel: true
            },
            axisLabel: {
              interval: 0,
              rotate: 30
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            data: this.category.value
          }
        ]
      };
      myChart.setOption(option)
    })


  }
}
</script>

<style lang="less">
.overview {
  padding: 25px 10px;
  background-color: #fff;

  h3 {
    color: #696969;
    font-size: 22px;
  }

  .title {
    display: flex;
    margin: 30px 0;

    .device-count,
    .money-count {
      width: 216px;
      height: 96px;
      color: #ab7df6;
      display: flex;
      font-size: 30px;
      align-items: center;
      border-radius: 6px;
      justify-content: space-evenly;
      background-color: #eee5fd;

      i {
        font-size: 40px;
        color: #ab7df6;
      }

      p {
        display: flex;
        align-items: center;
        flex-direction: column;

        span {
          font-size: 12px;

          &:last-child {
            font-size: 30px;
          }
        }
      }
    }

    .money-count {
      color: #81c926;
      margin-left: 34px;
      background-color: #e6f4d4;

      i {
        color: #81c926;
      }
    }
  }

  .tu {
    display: flex;
    height: 410px;
    border-radius: 10px;


    .circleView {
      width: 430px;
      background-color: #f3f3f3;
    }

    .treeView {
      width: 670px;
      margin-left: 20px;
      background-color: #f3f3f3;
    }
  }
}
</style>